/**
 * @file filter
 * @author liaoxuezhi@baidu.com
 */
/* eslint fecs-indent: [0, "space", 2, 2] */

import * as React from 'react';
import {
  Component,
  PropTypes
} from 'react';
import {filter} from '../../renderer';
import * as cx from 'classnames';
import Html from '../../../widgets/html';
import {Enhance as FormItem} from '../form-item';

@FormItem({
  type: 'static',
  attachForm: false,
  validateSchema: 'http://amis.baidu.com/schemas/form.json#/definitions/static'
})
export default class FormStatic extends Component {
  static propTypes = {
    className: PropTypes.string,
    formMode: PropTypes.string,
    formHorizontal: PropTypes.object,
    inputClassName: PropTypes.string
  };

  static defaultProps = {
    value: '',
    placeholder: '-'
  };

  render() {
    let {
      placeholder,
      value,
      data,
      tpl,
      text,
      inputClassName,
    } = this.props;

    if (value && typeof value === 'object') {
      value = JSON.stringify(value, null, 2)
    }

    return (
      <div
        className={cx('form-control-static', inputClassName)}
        key="input"
        >{tpl ? <Html html={filter(tpl, value, data)} /> : (value || text || (placeholder && (<span className="text-muted">{placeholder}</span>)))}</div>
    );
  }
}
